package com.subaiqiao.yunshiyuan.entrance.ysy.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.subaiqiao.yunshiyuan.basis.utils.Result;
import com.subaiqiao.yunshiyuan.entrance.ysy.pojo.SysCity;
import com.subaiqiao.yunshiyuan.entrance.ysy.service.SysCityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 曹朝禹
 * @since 2022-05-13
 */
@RestController
@RequestMapping("/ysy/sys-city")
@Api(tags = "城市管理")
public class SysCityController {

    @Autowired
    private SysCityService sysCityService;

    @ApiOperation("查询所有省市县信息")
    @GetMapping("/FindCity.do")
    public Result FindCity(@RequestParam(defaultValue = "") @ApiParam("父级省编号") Integer code){
        QueryWrapper<SysCity> wrapper = new QueryWrapper<>();
        if(code==null){
            wrapper.isNull("sys_city_parent_code");
        }else{
            wrapper.eq("sys_city_parent_code",code);
        }
        return Result.success(sysCityService.list(wrapper));
    }

    @ApiOperation("查询城市信息")
    @GetMapping("/FindCityDetails.do")
    public Result FindCityDetails(@RequestParam(defaultValue = "") @ApiParam("省级编号") Integer code,
                                  @RequestParam(defaultValue = "") @ApiParam("省级名称") String name){
        QueryWrapper<SysCity> wrapper = new QueryWrapper<>();
        if(code!=null){
            wrapper.eq("sys_city_code",code);
        }else{
            wrapper.eq("sys_city_name", name);
        }
        return Result.success(sysCityService.list(wrapper));
    }

}
